Skip to content

Ocarina of Time: a RomFS .zs file that is not a zstd stream is served as a profile-named substitute, ending a background reload loop (CPU 412% → 180% on the Mac) - #1530

Closed
aksmith-git wants to merge 2 commits into
seedds:mainfrom
aksmith-git:pr/romfs-zstd-subst

Conversation

@aksmith-git

@aksmith-git aksmith-git commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

In Ocarina of Time (Switch 2, 0400486024DEC000, update v131072) the game's background model loader never went idle: the OptimizeChangeBanc thread used about one core and a ParallelDecompThread about 0.75 core for the whole session, the process at about 400% CPU on the Mac. The cause is a RomFS texture that cannot be decompressed in the dump we have. This PR has the host serve such a file as a substitute the profile names, and the Ocarina of Time profile names one for each of the three files affected.

Cause

  • With DM_FS=1, Model/Land_FairyFountain_Base_A.Land_FairyFountain_Base_A_01.bfres.zs (2.4 MB) and Tex/CmnTex_Map_Soil_FairyFountain_Floor_D_Nrm.bntx.zs were each opened 2,095 times in about 95 s (about 22 a second). Every other file was opened 12 times or fewer.
  • That texture begins with 12,288 zero bytes, so it has no zstd frame header. A scan of all 102,185 .zs files in the RomFS found two more like it: Tex/Rock_WaterTemple_Gate_M_01_Nrm.bntx.zs and Tex/RBake_Scene_GanonStage_G_2_1_d0_t0.bntx.zs.
  • OptimizeChangeBanc (main+0xf7a0) loops over the area's 852 entries and goes back to its 16 ms sleep only after a pass in which every entry is done. Probes showed one entry that never finished, the Kokiri Forest fairy fountain model (Land_FairyFountain…). The game requested it again on every pass, and ParallelDecompThread decompressed the 2.4 MB model each time.
  • Where the damage comes from: these files are like this in the NUP we packed from. The container's SHA-256 of each file matches its contents, so the bytes were already this way when the NUP was packed. We don't know whether a retail copy has them. No other contributor's notes, issues or PRs mention these files or this loop. A NUP or dump folder has no NCA hashes to check, so extraction can't flag this kind of damage the way it flags a damaged NSP's files.
  • Returning "not found" for the file isn't enough. The game then asks for the .bntx, which isn't there either, and still fails the model (1,706 reloads in a test run).

Fix

  • hle_fs.c img_serve reads the first 4 bytes of a RomFS image file named *.zs once per entry, at its first OpenFile or GetEntryType, and records the result in memory. If the file starts with neither a zstd frame nor a skippable frame:

    • it is served as the file named for it by the new profile key romfs_substitute, which takes <path>=<substitute path> pairs (DM_ROMFS_SUBST replaces the list);
    • if no substitute is named, it is answered "not found";
    • either way, one [RED] line names the file.

    DM_ROMFS_ZSTD_CHECK=0 serves such files as stored. Every other file is served exactly as before, including every file in a copy without the damage.

  • Ocarina of Time profile:

    • both normal maps are served as the game's own 1x1 flat normal map, Tex/Dummy_Flat_Normal_CmnTex_Chara_DetailMap_Nrm.bntx.zs;
    • the Ganon stage bake is served as its neighbour cell's, ..._G_2_2_d0_t0 (not checked in game).

    All three substitutes are already in the RomFS, so an existing RomFS.img works as it is.

  • Second commit: a small diagnostic used to find this. DM_PROBE_EVERY=N counts every probe hit and prints every N-th one, so a probe's # gives a hit rate without printing a line per hit.

  • Docs:

    • a new entry in docs/reference/packing.md, under Damaged packages, and the symptom index regenerated;
    • the key in dm/games/README.md;
    • the env switches in docs/env_switches.tsv;
    • the game note.

Measurements

Mac (M4 Pro), 5-minute runs in Kokiri Forest, medians of the windows from frame 5000:

before after
process CPU 412% 180%
OptimizeChangeBanc / ParallelDecompThread in the top five all session idle after frame ~3900
submit CPU per frame 8.9 ms 5.7 ms
frame p50 17.7 ms 17.3 ms
frame p95 21.9 ms 18.8 ms

The model and its texture are now opened once each. Screenshots of the village and the Saria scene match the runs before the change. The loop also ran on an iPad, where OptimizeChangeBanc took about the same CPU time as on the Mac. This PR's branch has not been run on an iPad.

Tests

  • make -C dm/host GAME=0400486024DEC000 -j6 dmhost builds.
  • dm/host/tests/build/t_fs: 148 checks, 0 failed. The new checks cover:
    • a zstd stream is served as stored;
    • a .zs file of zeros is "not found" by entry type and by open, and is checked only once;
    • with a substitute named, the file is served as the substitute;
    • a substitute that isn't in the image is "not found".
  • python3 -m unittest passes for test_docs, test_env_switches and test_game_profile, and docs_symptoms.py --check reports the index is current.

Adrian Smith added 2 commits November 7, 2026 03:03
…# the true hit count (rates of a loop's branches without a line per hit)
…ofile's romfs_substitute, else "not found"; Ocarina of Time's three damaged textures substituted

The Ocarina of Time NUP at hand holds Tex/CmnTex_Map_Soil_FairyFountain_Floor_D_Nrm.bntx.zs, Tex/Rock_WaterTemple_Gate_M_01_Nrm.bntx.zs and Tex/RBake_Scene_GanonStage_G_2_1_d0_t0.bntx.zs with their first 12 KB zeroed (the container's SHA-256 of them matches, so they were so when it was packed; whether a retail copy has them is not known). The first kept the Kokiri Forest fairy fountain model from loading, so the OptimizeChangeBanc thread (main+0xf7a0, priority 55) never finished its pass over the area's 852 entries and asked for the model again ~22 times a second for the whole session: ~980 ms/s of CPU on the Mac and the iPad, plus ~750 ms/s of ParallelDecompThread decompressing the 2.4 MB model each time.

hle_fs.c img_serve checks a .zs image file's first 4 bytes once (open and entry type). A damaged one is served as the substitute the new profile key romfs_substitute names (DM_ROMFS_SUBST overrides; DM_ROMFS_ZSTD_CHECK=0 serves it as stored), else answered "not found" ("not found" alone still fails the model). Ocarina of Time's profile serves the two normal maps as the game's own 1x1 flat normal and the Ganon stage bake as its neighbour cell's.

Mac, 5-minute runs in Kokiri Forest, windows from frame 5000: CPU 412% -> 180%, OptimizeChangeBanc and ParallelDecompThread out of the top five (idle after frame ~3900), frame p50 17.7 -> 17.3 ms, p95 21.9 -> 18.8, submit CPU 8.9 -> 5.7 ms a frame. Test: t_fs (148 checks). Documented in docs/reference/packing.md (symptom index regenerated).
@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) docs Documentation game: 0400486024DEC000 A game labels Nov 6, 2026
seedds added a commit that referenced this pull request Nov 6, 2026
…# the true hit count (rates of a loop's branches without a line per hit) (from PR #1530)

Co-authored-by: aksmith-git <242086076+aksmith-git@users.noreply.github.com>
seedds added a commit that referenced this pull request Nov 6, 2026
…ge's .zs files must start with a zstd frame, as an NSP's files must pass the NCA's hashes; a contributor's Ocarina of Time NUP held three .zs textures beginning with zeros, which its background loader reloaded for ever (412% CPU, PR #1530)

- romfs_image.format_mismatches reads the first bytes of each file whose name promises a format (FORMAT_HEADS: .zs, a zstd frame or a skippable frame), in image order, no further than the file's own bytes; empty files are left out.
- The NSP script's check_formats runs after extraction for NSPs, NUPs and dumps, stops naming the files (pack again from a good copy), and lists them and goes on with --allow-damaged. The result stays in RomFS.img.formats beside the image until the image changes (Ocarina of Time: 102,185 .zs files, 16 s cold from a USB SSD; none damaged in this repository's copy).
- In place of PR #1530's run-time substitution, which served other textures for the damaged ones: the host serves a game's files as they are.
- Reference entry in packing.md, symptom index, Ocarina of Time note. Unit test; check_formats run on Ocarina of Time's image and on a synthetic damaged one. No game run.
@seedds

seedds commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Thanks for the careful measurements: they found something real, but in the game files rather than the game. Our NUP of the same version (v131072) has all three files as zstd streams (Land_FairyFountain… model's texture CmnTex_Map_Soil_FairyFountain_Floor_D_Nrm, Rock_WaterTemple_Gate_M_01_Nrm, RBake_Scene_GanonStage_G_2_1_d0_t0), and none of its 102,185 .zs files fails the zstd check. So the zeros are damage in the NUP you packed from, which, as you noted, has no NCA hashes to catch it.

What landed instead:

  • d0182aa: your DM_PROBE_EVERY commit, unchanged, with you credited as co-author.
  • 6bbdbbe: the NSP script now checks every extracted image at pack time: a file whose name promises a format and whose bytes don't match (a .zs that isn't a zstd stream) stops the build and names the files; --allow-damaged lists them and goes on. That would have flagged your NUP before any build. Reference: docs/reference/packing.md, "A damaged file in a NUP or a dump has no hash to fail".

The host keeps serving a game's files as they are: substituting other textures would hide the damage (and change what the game draws), so the host substitution and the profile rows aren't taken. Please repack from a good dump; with that, the loader should go idle as in your after-run, without any substitution.

@seedds seedds closed this Nov 6, 2026
@santissimoo

santissimoo commented Nov 7, 2026 •

Copy link
Copy Markdown

Another data point on the damage source. A second NUP of v131072, made independently by a different person, has the same three files damaged in the same way. 6bbdbbe's check names exactly these:

  • Tex/CmnTex_Map_Soil_FairyFountain_Floor_D_Nrm.bntx.zs (216,015 bytes)
  • Tex/RBake_Scene_GanonStage_G_2_1_d0_t0.bntx.zs (1,901,341 bytes)
  • Tex/Rock_WaterTemple_Gate_M_01_Nrm.bntx.zs (452,972 bytes)

Each starts with zeros. Two unrelated copies with identical damage points at the dumping or packing tool, not a bad read. So more NUPs in circulation probably carry it. With this PR's substitutes the host logged the swap for two of them in Kokiri Forest. I didn't measure CPU in that session.

— Claude, Santi's agent

@lunks

lunks commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for the second NUP. The reporter of #1605 also had Tex/CmnTex_Map_Soil_FairyFountain_Floor_D_Nrm.bntx.zs reported as damaged in a NUP of v131072 (his log names that file; I don't know about the other two). So at least three NUPs in circulation carry it, which may be a reason to reconsider a substitute for these files rather than only a build-time stop. Only a thought; the check in 6bbdbbe already names them.

gnosticgeek added a commit to gnosticgeek/nxforge that referenced this pull request Nov 7, 2026
…mg), which the packers still take; test_xcode_workflow's fixtures stopped on FileNotFoundError since upstream's format check (seedds#1530)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016qteK3qWJVi2jG3Gz4i1eY
Aeonitis pushed a commit to Aeonitis/nxnative that referenced this pull request Nov 7, 2026
…ixes (chain 844bf1a5ea8f, exactly upstream's), raw pool table words at commit (seedds#1427), incremental pool tables (seedds#1489), ocarina input stream (seedds#1527), damaged .zs check (seedds#1530)

Conflicts: chain tools and shader_split.py taken from upstream (dmsh_depth.py dropped: upstream compiles the 259-bracket shaders its own way); the build script keeps shader.noindex and takes upstream's progress watch; docs keep both packing entries.
Aznracer pushed a commit to Aznracer/Mighty-Green-Kokiri-Kid that referenced this pull request Nov 8, 2026
…# the true hit count (rates of a loop's branches without a line per hit) (from PR seedds#1530)
RedSolos pushed a commit to RedSolos/ocarina that referenced this pull request Nov 9, 2026
…textures

The NSP script's check stopped a player's build on the same three .zs files as the contributor's NUP (PR seedds#1530), two with 12,288 leading zero bytes and the Water Temple gate with 8,192: one damaged release in circulation, it seems, rather than one bad download.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ivan-leschinsky pushed a commit to ivan-leschinsky/nxnative that referenced this pull request Nov 9, 2026
…ofile's romfs_substitute, else "not found"; Ocarina of Time's three damaged textures substituted

The Ocarina of Time NUP at hand holds Tex/CmnTex_Map_Soil_FairyFountain_Floor_D_Nrm.bntx.zs, Tex/Rock_WaterTemple_Gate_M_01_Nrm.bntx.zs and Tex/RBake_Scene_GanonStage_G_2_1_d0_t0.bntx.zs with their first 12 KB zeroed (the container's SHA-256 of them matches, so they were so when it was packed; whether a retail copy has them is not known). The first kept the Kokiri Forest fairy fountain model from loading, so the OptimizeChangeBanc thread (main+0xf7a0, priority 55) never finished its pass over the area's 852 entries and asked for the model again ~22 times a second for the whole session: ~980 ms/s of CPU on the Mac and the iPad, plus ~750 ms/s of ParallelDecompThread decompressing the 2.4 MB model each time.

hle_fs.c img_serve checks a .zs image file's first 4 bytes once (open and entry type). A damaged one is served as the substitute the new profile key romfs_substitute names (DM_ROMFS_SUBST overrides; DM_ROMFS_ZSTD_CHECK=0 serves it as stored), else answered "not found" ("not found" alone still fails the model). Ocarina of Time's profile serves the two normal maps as the game's own 1x1 flat normal and the Ganon stage bake as its neighbour cell's.

Mac, 5-minute runs in Kokiri Forest, windows from frame 5000: CPU 412% -> 180%, OptimizeChangeBanc and ParallelDecompThread out of the top five (idle after frame ~3900), frame p50 17.7 -> 17.3 ms, p95 21.9 -> 18.8, submit CPU 8.9 -> 5.7 ms a frame. Test: t_fs (148 checks). Documented in docs/reference/packing.md (symptom index regenerated).

Ported from seedds#1530 (closed upstream, which keeps serving damaged files as they are and stops the build instead, 6bbdbbe) for this fork: the NUP these builds are packed from has the same three files zeroed (RomFS.img.formats), as two other v131072 NUPs do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U35V38c6UYLbzyyPx6Up7P
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…# the true hit count (rates of a loop's branches without a line per hit) (from PR seedds#1530)

Co-authored-by: aksmith-git <242086076+aksmith-git@users.noreply.github.com>
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…ge's .zs files must start with a zstd frame, as an NSP's files must pass the NCA's hashes; a contributor's Ocarina of Time NUP held three .zs textures beginning with zeros, which its background loader reloaded for ever (412% CPU, PR seedds#1530)

- romfs_image.format_mismatches reads the first bytes of each file whose name promises a format (FORMAT_HEADS: .zs, a zstd frame or a skippable frame), in image order, no further than the file's own bytes; empty files are left out.
- The NSP script's check_formats runs after extraction for NSPs, NUPs and dumps, stops naming the files (pack again from a good copy), and lists them and goes on with --allow-damaged. The result stays in RomFS.img.formats beside the image until the image changes (Ocarina of Time: 102,185 .zs files, 16 s cold from a USB SSD; none damaged in this repository's copy).
- In place of PR seedds#1530's run-time substitution, which served other textures for the damaged ones: the host serves a game's files as they are.
- Reference entry in packing.md, symptom index, Ocarina of Time note. Unit test; check_formats run on Ocarina of Time's image and on a synthetic damaged one. No game run.
Fasen24-AI added a commit to Fasen24-AI/swordboiMacNative that referenced this pull request Nov 10, 2026
…td stream is served as a profile-named substitute, ending a background reload loop (CPU 412% → 180% on the Mac)

Upstream pull requests applied in this commit (their authors' work, brought onto this tree with a three-way merge; the description is in each PR):
- seedds#1530 by aksmith-git (closed): Ocarina of Time: a RomFS .zs file that is not a zstd stream is served as a profile-named substitute, ending a background reload loop (CPU 412% → 180% on the Mac)
RedSolos pushed a commit to RedSolos/ocarina that referenced this pull request Nov 10, 2026
…textures

The NSP script's check stopped a player's build on the same three .zs files as the contributor's NUP (PR seedds#1530), two with 12,288 leading zero bytes and the Water Temple gate with 8,192: one damaged release in circulation, it seems, rather than one bad download.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RedSolos pushed a commit to RedSolos/ocarina that referenced this pull request Nov 11, 2026
…textures

The NSP script's check stopped a player's build on the same three .zs files as the contributor's NUP (PR seedds#1530), two with 12,288 leading zero bytes and the Water Temple gate with 8,192: one damaged release in circulation, it seems, rather than one bad download.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RedSolos pushed a commit to RedSolos/ocarina that referenced this pull request Nov 15, 2026
…textures

The NSP script's check stopped a player's build on the same three .zs files as the contributor's NUP (PR seedds#1530), two with 12,288 leading zero bytes and the Water Temple gate with 8,192: one damaged release in circulation, it seems, rather than one bad download.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation game: 0400486024DEC000 A game host The Horizon host: SVCs, services, threads, memory (dm/host)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants